package web

import (
	"bytes"

	"xp/lib/mux"
)

const (
	ajaxCallHeader = `X-Requested-With`
)

var (
	wechatBrowser = []byte(`micromessenger`)
	ajaxCallValue = []byte(`XMLHttpRequest`)
)

func FromWechat(ctx *mux.Ctx) bool {
	return bytes.Contains(bytes.ToLower(ctx.UserAgent()), wechatBrowser)
}

func IsAjax(ctx *mux.Ctx) bool {
	return bytes.Equal(ctx.GetHeader(ajaxCallHeader), ajaxCallValue)
}
